/***********************************************
 This file is part of redia-bapps-main-ios.
 
 Copyright (c) 2015 Redia A/S
 
 Redia-bapps-main-ios is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Redia-bapps-main-ios is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with redia-bapps-main-ios.  If not, see <http://www.gnu.org/licenses/>.
 
 *********************************************** */

//
//  BAUtils.m
//  redia-bapps-ios
//
//  Created by Henrik Lynbech on 09/08/13.
//  Copyright (c) 2013 redia. All rights reserved.
//

#import "BAUtils.h"
#import "UIImage+MultiplyColor.h"
#import "BALibrary.h"
#import "BALibrarySettings.h"

@implementation BAUtils

SINGLETON_IMPL_GCD(BAUtils)

- (id)init
{
    self = [super init];
    if (self) {
        self.whiteBackButtonImage = [UIImage imageNamed:@"backbutton-white"];
        self.grayBackButtonImage = [UIImage imageNamed:@"backbutton-white" multiplyWithColor:[UIColor colorWithWhite:102.0/255.0 alpha:1]];
        self.whiteTopRightMenu = [UIImage imageNamed:@"menu-top-right"];
        self.grayTopRightMenu = [UIImage imageNamed:@"menu-top-right" multiplyWithColor:[UIColor colorWithWhite:102.0/255.0 alpha:1]];
        
        if (RD_IS_IPAD) {
            self.iPadWhiteTopLeftClose = [UIImage imageNamed:@"navbar-close"];
            self.iPadGrayTopLeftClose = [UIImage imageNamed:@"navbar-close" multiplyWithColor:[UIColor colorWithWhite:102.0/255.0 alpha:1]];
        }
        
        // Get the major version of iOS.
        NSString *versionString = [[UIDevice currentDevice] systemVersion];
        self.iOSMajorVersion = [[[versionString componentsSeparatedByString:@"."] objectAtIndex:0] integerValue];
        
    }
    return self;
}

+(NSString *)makeCommaSeparatedStringFromStrings:(NSArray *)stringArray
{
    NSMutableString* strings_cat = [NSMutableString new];
    for (int i=0; i<[stringArray count]; i++) {
        NSString* s = [stringArray objectAtIndex:i];
        if (i<[stringArray count]-1) {
            [strings_cat appendFormat:@"%@, ",s];
        } else {
            [strings_cat appendString:s];
        }
        
    }
    return [NSString stringWithString:strings_cat];
}

/* getLibrariesAsyncFromView is deprecated, needs new impl
+(void)hardWireToCustomerId:(NSString*)customerId resultBlock:(void(^)())resultBlock
{
    DLog(@"fetching libraries...");
    [BARPCManager getLibrariesAsyncFromView:self
                                resultBlock:^(NSArray *result) {
                                    BOOL found = NO;
                                    for (BALibrary* lib in result) {
                                        if ([lib.customerId isEqualToString:customerId]) {
                                            [[BARPCManager instance] setAndConfigureLibraryId:lib.customerId];
                                            
                                            [BALibrarySettings instance].libraryObject = lib;
                                            found=YES;
                                            resultBlock();

                                        }
                                    }
                                    if (!found) {
                                        ALog(@"ERROR library %@ not found in list!!", customerId);
                                    }
                                }
                                 errorBlock:^(int code, NSString *error) {
                                     UIAlertView* v = [[UIAlertView alloc] initWithTitle:@"Netværksproblemer" message:@"Kunne ikke hente listen af biblioteker" delegate:self cancelButtonTitle:@"Prøv igen" otherButtonTitles:nil];
                                     [v show];
                                 }
     ];
}
*/

+(void)setViewToFillParent:(UIView*)view{
    if (view.superview != nil) {
        view.translatesAutoresizingMaskIntoConstraints = NO;
        
        [view.superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics: 0 views:NSDictionaryOfVariableBindings(view)]];
        [view.superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics: 0 views:NSDictionaryOfVariableBindings(view)]];
    }
}

@end
